/**
 * 
 */
package edu.unr.cater.npap.server.security;

import java.util.ArrayList;
import java.util.Collection;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;

/**
 * @author Hao
 * 
 */
public class CustomUserAuthentication implements Authentication {
	private static final long serialVersionUID = -3091441742758356129L;

	private boolean authenticated;

	private GrantedAuthority grantedAuthority;

	private Authentication authentication;

	public CustomUserAuthentication(String role, Authentication authentication) {
		this.grantedAuthority = new GrantedAuthorityImpl(role);
		this.authentication = authentication;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.security.Principal#getName()
	 */
	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return this.getClass().getSimpleName();

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.security.core.Authentication#getAuthorities()
	 */
	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		// TODO Auto-generated method stub
		Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
		authorities.add(grantedAuthority);
		return authorities;

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.security.core.Authentication#getCredentials()
	 */
	@Override
	public Object getCredentials() {
		// TODO Auto-generated method stub
		return authentication.getCredentials();

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.security.core.Authentication#getDetails()
	 */
	@Override
	public Object getDetails() {
		// TODO Auto-generated method stub
		return authentication.getDetails();

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.security.core.Authentication#getPrincipal()
	 */
	@Override
	public Object getPrincipal() {
		// TODO Auto-generated method stub
		return authentication.getPrincipal();

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.security.core.Authentication#isAuthenticated()
	 */
	@Override
	public boolean isAuthenticated() {
		// TODO Auto-generated method stub
		return authenticated;

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.springframework.security.core.Authentication#setAuthenticated(boolean
	 * )
	 */
	@Override
	public void setAuthenticated(boolean arg0) throws IllegalArgumentException {
		// TODO Auto-generated method stub
		this.authenticated = arg0;

	}

}
